***************************************
****  	Table 2: EXPENDITURE  ****
***************************************


use "$dir/Data/analysis_expenditure.dta", clear

eststo clear

foreach x in loancredit_any {
	gen temp1 =`x' if postpay_3d==1
	egen temp2 = max(temp1), by(pid)
	eststo a1: areg temp2 cash blhrprod_miss canget1k_miss ownland_miss bs_labor_7_miss bs_labor_30_miss future_fin_worry_miss if pid1==1, cluster(pid) a(roundgroup)
	qui summarize temp2 if cash==0 & pid1==1
	qui estadd scalar cont = r(mean)
	drop temp*
}

local i = 2
foreach x in loancredit tothhexpense foodexp dressexp dailyexp medicexp tobaccoexp totexpense_top{
	gen temp1 =`x' if postpay_3d==1
	egen temp2 = total(temp1), by(pid)
	eststo a`i': areg temp2 cash blhrprod_miss canget1k_miss ownland_miss bs_labor_7_miss bs_labor_30_miss future_fin_worry_miss if pid1==1, cluster(pid) a(roundgroup)
	qui summarize temp2 if cash==0 & pid1==1
	qui estadd scalar cont = r(mean)
	drop temp*
	local i = `i' + 1
}

#delimit ;
local tablerow cash;

esttab a2 a1 a3 a4 a5 a6 a7 a8 a9 using "$om/$t/Table_2A.tex", 
    b(2) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles nonumbers
    replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
    stats(cont N, labels("Control group mean" "N: workers") fmt(%9.2fc %9.0fc)) 
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
	\begin{tabular}     
	{@{\extracolsep{5pt}}p{6.7cm}*{8}{>{\centering\arraybackslash}m{2cm}}*{1}{>{\centering\arraybackslash}m{3cm}}@{}}    
	\toprule   \addlinespace                   
	&\multicolumn{2}{c}{\textbf{Loans and Credits}}  & \multicolumn{6}{c}{\textbf{Household}} & \multicolumn{1}{c}{\textbf{Total}}  \\
	&\multicolumn{2}{c}{ }  & \multicolumn{6}{c}{\textbf{expenditures}} & \multicolumn{1}{c}{\textbf{expenditures}}  \\
	\cline{2-3} \cline{4-9} \cline{10-10} \addlinespace
	& Amount  & Any Payment  & Total & Food & Clothes & HH essentials & Medical & Tobacco/ alcohol & Amount  \\
	& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9)   \\
	\midrule \addlinespace 
	\multicolumn{6}{l}{\textbf{PANEL A: Overall Impacts}}      
	\bigstrut          \\ ") ;
		
#delimit cr	



** expenditure on each day

local i = 1
eststo clear
foreach x in loancredit loancredit_any tothhexpense foodexp dressexp dailyexp medicexp tobaccoexp totexpense_top {
	eststo b`i': areg `x' cash_1st cash_2nd cash_3rd blhrprod_miss canget1k_miss ownland_miss bs_labor_7_miss bs_labor_30_miss future_fin_worry_miss if postpay_3d==1, cluster(pid) a(roundgroupdayago)
	qui summarize `x' if cash==0 & postpay==1 & postpay_3d==1
	qui estadd scalar cont = r(mean)
	qui summarize `x' if cash==0 & postpay==1 & all_1st==1
	qui estadd scalar cont1 = r(mean)
	local i = `i' + 1
}

#delimit ;
local tablerow cash_1st cash_2nd cash_3rd;

esttab using "$om/$t/Table_2B.tex", 
    b(2) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles nonumbers
    replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
    stats(cont cont1 N, labels("Control group mean" "Control group mean, day of payment" "N: worker-days") fmt(%9.2fc %9.2fc %9.0fc)) 
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
	\begin{tabular}     
	{@{\extracolsep{5pt}}p{6.7cm}*{8}{>{\centering\arraybackslash}m{2cm}}*{1}{>{\centering\arraybackslash}m{3cm}}@{}} 
	\toprule          
	\multicolumn{6}{l}{\textbf{PANEL B: Daily Impacts}}       
	\bigstrut    \\
	") ;
		
#delimit cr		

